﻿Public Class IngresarInventarios
    Inherits System.Web.UI.Page
    Dim c As New Conexion
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("VariableNombre") = Nothing Then
            Label1.Text = "Tienes que Logearte"
            btnLogout.Visible = False
        Else
            HyperLink1.Visible = False
            Label2.Text = "Bienvenido " + Session("VariableNombre").ToString()

            c.SeleccionarLetras(TextBox6, "select nombres from usuarios where login='" & Session("VariableNombre").ToString() & "'")
            Label2.Text = "Bienvenido " + TextBox6.Text


        End If

        TextBox1.Enabled = True
        TextBox3.Enabled = True
        DropDownList1.Enabled = True
        DropDownList2.Enabled = False
        Image2.Enabled = True
        TextBox9.Enabled = False
        TextBox10.Enabled = False
        TextBox11.Enabled = False

        Button2.Enabled = False
        Button3.Enabled = False

    End Sub

    Protected Sub btnLogout_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLogout.Click
        Session("VariableNombre") = Nothing
        Response.Redirect("InicioSesion.aspx")
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Dim descripcion As String = TextBox1.Text
        Dim empleado As String = DropDownList1.SelectedItem.Text
        Dim fecha As String = TextBox3.Text


        c.Seleccionar(TextBox7, "select idempleado from empleados where nombres='" & empleado & "'")


        '    Dim idInventa As Integer = Convert.ToInt32(TextBox8.Text)

        Dim sentencia As String = "insert into inventario values('" & descripcion & "'," & TextBox7.Text & ",'" & fecha & "')"
        c.Insertar_Actualizar_Eliminar(sentencia, "insertados")
        Label1.Text = Conexion.msj_sql_server

        TextBox1.Enabled = False
        TextBox3.Enabled = False
        DropDownList1.Enabled = False
        Image2.Enabled = False
        DropDownList2.Enabled = True
        TextBox9.Enabled = True
        TextBox10.Enabled = True
        TextBox11.Enabled = True
        Button2.Enabled = True
        Button3.Enabled = True
        Button1.Enabled = False

    End Sub

    
    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click
        Dim producto As String = DropDownList2.SelectedItem.Text
        Dim peso As String = TextBox9.Text
        Dim cantidad As Integer = Convert.ToInt32(TextBox10.Text)
        Dim observacion As String = TextBox11.Text

        Dim descripcion As String = TextBox1.Text

        c.Seleccionar(TextBox12, "select idproducto from productos where descripcion='" & producto & "'")
        'Dim sentencia As String = "insert into descripcioninventario values(" & TextBox8.Text & "," & TextBox12.Text & ",'" & peso & "', " & cantidad & ", ' " & observacion & "')"

        c.Seleccionar(TextBox8, "select idinventario from inventario where descripcion='" & descripcion & "'")


        Dim sentencia As String = "insert into descripcioninventario values(" & TextBox8.Text & "," & TextBox12.Text & ",'" & peso & "', " & cantidad & ", ' " & observacion & "')"
        c.Insertar_Actualizar_Eliminar(sentencia, "insertados")
        Label3.Text = Conexion.msj_sql_server

        TextBox1.Enabled = False
        TextBox3.Enabled = False
        DropDownList1.Enabled = False
        Image2.Enabled = False
        DropDownList2.Enabled = True
        TextBox9.Enabled = True
        TextBox10.Enabled = True
        TextBox11.Enabled = True
        Button2.Enabled = True
        Button3.Enabled = True
        Button1.Enabled = False
    End Sub

    Protected Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
        Server.Transfer("index.aspx")
    End Sub
End Class